package com.tarzan.edu.controller;

import com.tarzan.common.core.base.BaseResponse;
import com.tarzan.common.core.exception.BusinessException;
import com.tarzan.edu.entity.EduVideo;
import com.tarzan.edu.entity.response.EduVideoResp;
import com.tarzan.edu.service.IEduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liujinshan
 * @title: EduVideoController
 * @projectName com.tarzan.edu.controller
 * @description: TODO 视频模块 控制层
 * @date 2021/5/25 14:52
 */
@RestController
@RequestMapping("edu/video")
public class EduVideoController {

    @Autowired
    private IEduVideoService iEduVideoService;

    /**
     * @title insert
     * @description TODO 插入小节
     * @param eduVideo
     * @return com.tarzan.common.core.base.BaseResponse
     * @author liujinshan
     * @data 2021/6/18 16:05
     */
    @PostMapping(value = "insert",consumes = {"application/json"},produces = {"application/json"})
    public BaseResponse insert(@RequestBody EduVideo eduVideo){
        try {
            iEduVideoService.insert(eduVideo);
        } catch (BusinessException e) {
            return BaseResponse.error(e.getCode(),e.getMsg());
        } catch (Exception e){
            return BaseResponse.error("500",e.getMessage());
        }
        return BaseResponse.ok();
    }

    @GetMapping("findVideoInfoById/{id}")
    public BaseResponse<EduVideoResp> findVideoInfoById(@PathVariable String id){
        BaseResponse<EduVideoResp> response = new BaseResponse<>();
        try {
            response = BaseResponse.ok(iEduVideoService.findVideoInfoById(id));
        } catch (BusinessException e) {
            return BaseResponse.error(e.getCode(),e.getMsg());
        } catch (Exception e){
            return BaseResponse.error("500",e.getMessage());
        }
        return response;
    }

}
